package com.sn.author.filter;


import com.sn.author.domain.BaseResult;
import com.sn.author.common.enums.ExceptionEnum;
import com.sn.author.utils.AESUtil;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author Jackies
 * @Date 2019/12/1 15:01
 * @Description TODO://
 **/
public class ApiRequestSupport {

    public static void invokeExceptionWrapper(HttpServletResponse response, Integer code, String message)
            throws Exception {
        BaseResult<Object> json = new BaseResult<>();
        json.setCode(code);
        json.setMessage(message);
        json.setData("");
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().write(AESUtil.encrypt(json.toJson()));
    }

    public static void invokeExceptionWrapper(HttpServletResponse response, ExceptionEnum exceptionEnum) throws Exception {
        invokeExceptionWrapper(response,exceptionEnum.getCode(),exceptionEnum.getMessage());
    }

}
